<script>
	const util = require("@/utils/util.js")
	export default {
		globalData: {
			share: false, // 分享默认为false
			referrerUserId: '', //分享的用户Id
			customBar: {
				width: 0,
				height: 0,
				top: 0,
				scrollH: 0
			},
			userInfo: {
				nickname: 'Hi,游客,点击头像登录',
				headImgUrl: '/static/images/mall/mine_def_touxiang_3x.png'
			},
			token: '',
			rechargeStatus: 2,
			tabName: '艾公馆',
			cardId: '',
		},
		onLaunch: function(options) {
			let that = this;
			uni.addInterceptor('navigateTo', {
				success(e) {
					let page = getCurrentPages()[getCurrentPages().length - 1].route // 获取栈实例
					console.log(page, e);
				}
			})
			uni.addInterceptor('navigateBack', {
				success(e) {
					let page = getCurrentPages()[getCurrentPages().length - 1].route // 获取栈实例
					console.log(page);
				}
			})
			// #ifdef APP-PLUS
			/* 接收消息通知并跳转到tab页面 */
			const _handlePush = function(message) {
				that.updatePushMessage(message);
			};
			plus.push.addEventListener('click', function(message) {
				// plus.nativeUI.toast('push click');
				_handlePush(message);
				uni.switchTab({
					url: '/pages/ucenter/index/index'
				});
			}, true);
			plus.push.addEventListener('receive', function(message) {
				// plus.nativeUI.toast('push receive');
				_handlePush(message);
			});
			// 获取App端cid
			let pinf = plus.push.getClientInfo();
			if (pinf && pinf.clientid) uni.setStorageSync('cid', pinf.clientid);
			else {
				var obtainingCIDTimer = setInterval(function() {
					pinf = plus.push.getClientInfo();
					if (pinf.clientid) {
						uni.setStorageSync('cid', pinf.clientid);
						clearInterval(obtainingCIDTimer);
					}
				}, 50);
			}
			setTimeout(() => {
				console.log('cid', uni.getStorageSync('cid'));
			}, 500)
			// #endif
			// end
			let obj = {
				top: 0,
				left: 0,
				height: 0
			}
			// #ifdef MP-WEIXIN
			//获取设备顶部窗口的高度（不同设备窗口高度不一样，根据这个来设置自定义导航栏的高度）
			obj = uni.getMenuButtonBoundingClientRect();
			if (options.scene == 1007 || options.scene == 1008) {
				this.globalData.share = true
			} else {
				this.globalData.share = false
			}
			if (uni.canIUse('getUpdateManager')) {
				const updateManager = uni.getUpdateManager();
				if (updateManager) {
					updateManager.onCheckForUpdate(function(res) {
						// 请求完新版本信息的回调
						if (res.hasUpdate) {
							updateManager.onUpdateReady(function() {
								util.modal('更新提示', '新版本已经上线啦~，为了获得更好的体验，建议立即更新', false, res => {
									// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
									updateManager.applyUpdate();
								});
							});
							updateManager.onUpdateFailed(function() {
								// 新的版本下载失败
								util.modal('更新失败', '新版本更新失败，为了获得更好的体验，请您删除当前小程序，重新搜索打开', false,
									res => {});
							});
						}
					});
				}
			}
			// #endif
			uni.getSystemInfo({
				success: (res) => {
					that.globalData.customBar.width = obj.left || res.windowWidth
					that.globalData.customBar.height = obj.top ? (obj.top + obj.height + 8) : (res
						.statusBarHeight + 44)
					that.globalData.customBar.top = obj.top ? (obj.top + (obj.height - 32) / 2) : (res
						.statusBarHeight + 6)
					that.globalData.customBar.scrollH = res.windowWidth * 0.6
				}
			})

			// util.request('common/sendSmsCode',{
			// 	phone: '13882226757',
			// 	useType: 1
			// },'POST').then(res => {
			// 	if (res.code === 0) {
			// 		console.log(res);
			// 	}
			// });
		},
		onShow: function() {},
		onHide: function() {
			//console.log('App Hide')
		},
		onError: function(err) {
			//全局错误监听
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, widgetInfo => {
				const res = uni.getSystemInfoSync();
				let errMsg =
					`手机品牌：${res.brand}；手机型号：${res.model}；操作系统版本：${res.system}；客户端平台：${res.platform}；错误描述：${err}`;
				console.log('发生错误：' + errMsg);
			});
			// #endif
		},
		methods: {
			updatePushMessage(msg) {
				console.log(msg);
			}
		}
	};
</script>

<style>
	/*每个页面公共css uParse为优化版本*/
	@import './common/app.css';
	/* #ifndef APP-NVUE */
	@import './components/uni/uParse/src/wxParse.css';
	/* #endif */
	/**app.wxss**/
	.containers {
	  height: auto;
	  display: flex;
	  flex-direction: column;
	  align-items: center;
	  /* justify-content: space-between; */
	  /*padding: 200rpx 0;*/
	  box-sizing: border-box;
	}
	
	/**app.wxss**/
	.containers_login{
	  height: 100%;
	  display: flex;
	  flex-direction: column;
	  align-items: center;
	  justify-content: space-between;
	  padding: 60rpx 0;
	  box-sizing: border-box;
	  
	} 
	
	.containers.withtab{
	  margin: 0dp 0 0 0;
	  /*top: 105rpx;*/
	}
	.flex-wrp{
	  display: flex;
	}
	.flex-tab{
	  flex-flow: row nowrap;
	  justify-content: space-around;
	  align-items: stretch;
	}
	.flex-item{
	  flex-grow: 1;
	  text-align: center;
	}
	.top-tab{
	  width: 750rpx;
	  height: 100rpx;
	  background: #298DE5;
	  color: #8CCEFD;
	  font-size: 28rpx;
	  line-height: 100rpx;
	  box-shadow: 0 2px 2px #bebebe;
	  margin: 0 0 8rpx 0;
	  position: fixed;
	  top: 0;
	  z-index: 9999;
	}
	.toptab.active{
	  color: #ffffff;
	  border-bottom: solid 2px #ffffff;
	}
	.containers{
	  padding: 0;
	  font-size: 14rpx;
	  color: #000;
	}
	.containers .feed-item{
	  width: 690rpx;
	  padding: 30rpx 30rpx 20rpx;
	  margin: 7rpx 0 6rpx 0;
	  background: #ffffff;
	  border-top: 1px solid #eee;
	  border-bottom: 1px solid #eee;
	  box-shadow: 0 2px 5px #eeeeee;
	}
	.containers .feed-item .feed-source{
	  width: 690rpx;
	  left: 0;
	  height: 50rpx;
	}
	.containers .feed-item .feed-source .avatar{
	  position: relative;
	  display: inline-block;
	}
	.containers .feed-item .feed-source a{
	  display: inline-block;
	  height: 40rpx;
	}
	.containers .feed-item .feed-source .avatar image{
	  /*position: absolute;*/
	  display: inline-block;
	  width: 45rpx;
	  height: 45rpx;
	  border-radius: 45rpx;
	  top: 10rpx;
	  vertical-align: middle;
	}
	.containers .feed-item .feed-source text{
	  /*position: absolute;*/
	  display: inline-block;
	  height: 40rpx;
	  line-height: 40rpx;
	  vertical-align: middle;
	  margin: 0 0 0 15rpx;
	  color: #a0acac;
	  font-size: 26rpx;
	}
	.containers .feed-item .feed-source .item-more{
	  display: inline-block;
	  width: 40rpx;
	  height: 45rpx;
	  float: right;
	}
	.containers .feed-item .feed-content{
	  padding: 10rpx 0 0 0;
	  width: 300rpx;
	}
	.containers .feed-item .feed-content .question text{
	  font-size: 28rpx;
	  font-weight: 600px;
	  line-height: 40rpx;
	  text-space: 5rpx;
	}
	.containers .feed-item .feed-content .answer-body{
	  padding: 10rpx 0 0 0;
	  /*height: 10rpx;*/
	  font-size: 24rpx;
	  line-height: 28rpx;
	  color: #5b5b5b;
	}
	.containers .feed-item .feed-content .answer-actions{
	  width: 690rpx;
	  padding: 10rpx 0  0;
	  color: #a0acac;
	}
	.containers .feed-item .feed-content .answer-actions view{
	  display: inline-block;
	  vertical-align: text-bottom;
	  padding: 0 10rpx 0 0;
	  font-size: 24rpx;
	}
	.containers .feed-item .feed-content .answer-actions .dot ::after{
	  content: "•";
	}
</style>
